package com.hanyxx.thread.lambda;

/**
 * @author layman
 * @date 2021/3/2
 */
public class Demo04 {
    public static void main(String[] args) {
        //匿名内部类写法
        int sum = getSum(10, 20, new Calculator() {
            @Override
            public int getSum(int a, int b) {
                return a + b;
            }
        });
        System.out.println("求和sum为:" + sum);

        //标准lambda表达式写法
        int sum1 = getSum(30, 40, (int a, int b) -> {
                return a + b;
            }
        );
        System.out.println("求和sum1为:" + sum1);

        //lambda表达式省略写法
        int sum2 = getSum(50, 60, (a, b) ->
                     a + b
        );
        System.out.println("求和sum2为:" + sum2);
    }

    public static int getSum(int a,int b,Calculator calculator){
        int sum = calculator.getSum(a,b);
        return sum;
    }
}
interface Calculator {
    int getSum(int a,int b);
}
